<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/plugin/jquery-1.10.2.min.js"></script>
<title>Insert title here</title>
</head>
<body>
	<button id="btnHighRequest" type="button" onclick="highRequest()">高并发请求</button>
	<button id="btnWs" type="button" onclick="send_echo()">WS请求</button>
</body>
<script type="text/javascript">
	
	function highRequest() {
		for (var i = 0; i < 1000; i++) {
			reSend();
		}
	}

	function reSend() {
		window.setInterval(function() {
			sendRequest()
		}, 1);
	}

	function sendRequest() {
		$.ajax({
			url : "test/highRequest",
			type : "post",
			dataType : "application/json",
			data : {

			},
			success : function(data) {
				console.log(data);
			}
		});
	}
	
	var echo_websocket;
    function init() {
      output = document.getElementById("output");
    }
    
    $(function(){
    	var wsUri = "ws://127.0.0.1:8091/hiv/springws/websocket.ws";
		console.log("Connecting to " + wsUri);
		echo_websocket = new WebSocket(wsUri);
		echo_websocket.onopen = function(evt) {
			console.log("Connected !");
			//doSend("abcdefg");
		};
		echo_websocket.onmessage = function(evt) {
			console.log("Received message: " + evt.data);
		};
		echo_websocket.onerror = function(evt) {
			console.log("ERROR:" + evt.data);
			echo_websocket.close();
		};

		echo_websocket.onclose = function(event) {
			console.log("WebSocket:已关闭");
			console.log(event);
		};
    });
    
	
	function send_echo() {
		doSend("abcdefg");
	}

	function doSend(message) {
		console.log("Sent message: " + message);
		echo_websocket.send(message);
	}
</script>
</html>